import User from './components/user/index'
import Approval from './components/approval'
import Homepage from './components/homepage'
import Attendance from './components/attendance'
export default {
  components: {
    User,
    Approval,
    Homepage,
    Attendance,
  },
  data() {
    return {
      active: this.$store.state.homepageTabs,
      homepage: {
        default: '/static/homepage-default.svg',
        active: '/static/homepage-active.svg',
      },
      attendance: {
        default: '/static/meeting-default.svg',
        active: '/static/meeting-active.svg',
      },
      approval: {
        default: '/static/approval-default.svg',
        active: '/static/approval-active.svg',
      },
      user: {
        default: '/static/user-default.svg',
        active: '/static/user-active.svg',
      },
      currentTab: 'homepage',
      menu: ['homepage', 'attendance', 'approval', 'user'],
      attendanceReload: true,
      approvalReload: true,
    }
  },
  mounted() {
    this.currentTab = this.menu[this.$store.state.homepageTabs]
  },
  methods: {
    onChange(event) {
      this.active = event.mp.detail
      this.$store.commit('initHomepageTabs', event.mp.detail)
      this.currentTab = this.menu[event.mp.detail]
    },
  },
  onShow() {
    // 数据更新刷新组件
    if (this.currentTab === 'attendance') {
      this.attendanceReload === false
      setTimeout(() => {
        this.attendanceReload = true
      })
    } else if (this.currentTab === 'approval') {
      this.approvalReload = false
      setTimeout(() => {
        this.approvalReload = true
      })
    }
  },
}
